package com.jushu.storbox;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import com.handmark.pulltorefresh.library.PullToRefreshListView;
import com.jushu.storbox.constant.IntentConstant;
import com.jushu.storbox.constant.MessageCode;
import com.jushu.storbox.constant.UiConstant;
import com.jushu.storbox.entities.FileFolderInfo;
import com.jushu.storbox.entities.TeamSpaceInfo;
import com.jushu.storbox.newfragment.argument.TeamListActionArgs;
import com.jushu.storbox.view.resolve.TeamListResolve;

public class TeamFolderBrowserActivity extends BaseTitleActivity {

	TeamListResolve displayResolve = null;
	PullToRefreshListView dataShowView;

	String currentFolderId = "";

	Intent intent = null;
	Bundle bundle = null;
	FileFolderInfo srcObj = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_target_team_browser);
		switchTypeFive();
		currentTitle.setText(R.string.team_space);
		dataShowView = (PullToRefreshListView) findViewById(R.id.file_action_content_list);

		intent = getIntent();
		if (intent != null) {
			bundle = intent.getBundleExtra(IntentConstant.INTENT_SEARCH_TEAMSPACE_DATA);
		}
		if (bundle == null) {
			bundle = new Bundle();
		}
		displayResolve = new TeamListResolve(this, new TeamListActionArgs()) {
			public void openTeamspace(TeamSpaceInfo info) {
				Intent intent = new Intent(context, TargetFolderBrowserActivity.class);
				bundle.putString(IntentConstant.INTENT_TITLE_NAME, info.getName());
				bundle.putString(IntentConstant.INTENT_TARGET_RESOURCE_OWNER, info.getTeamSpaceId());
				bundle.putInt(IntentConstant.INTENT_COMEFROM_REQUEST, IntentConstant.INTENT_REQUEST_TRANSLATEFILE);//
				intent.putExtra(IntentConstant.INTENT_SEARCH_TARGET_DATA, bundle);
				startActivityForResult(intent, IntentConstant.INTENT_REQUEST_COPY_TEAM_TARGET);
			}
		};
		displayResolve.initComponent(dataShowView);
		displayResolve.binddingAdapter();
	}

	@Override
	public void onActivityResult(int requestCode, int resultCode, Intent data) {
		if (intent == null) {
			intent = new Intent();
		}
		switch (requestCode) {
		case IntentConstant.INTENT_REQUEST_COPY_TEAM_TARGET:
			switch (resultCode) {
			case MessageCode.TRANSFER_TO_MY_TEAM_SUCCESS: // 单个转存到团队空间成功
				setResult(MessageCode.TRANSFER_TO_MY_TEAM_SUCCESS, intent);
				finish();
				break;
			case UiConstant.SHARE_ACTION_SAVE_CANCEL: // 单个转存到团队空间（取消自动重命名）
				setResult(UiConstant.SHARE_ACTION_SAVE_CANCEL, intent);
				finish();
				break;

			case UiConstant.NODES_ACTION_COPY_ALL_SUCCESS: // 批量转存到团队空间成功
				setResult(UiConstant.NODES_ACTION_COPY_ALL_SUCCESS, intent);
				finish();
				break;

			case UiConstant.NODES_ACTION_COPY_SOME_SUCCESS: // 批量转存到团队空间(部分成功)
				setResult(UiConstant.NODES_ACTION_COPY_SOME_SUCCESS, intent);
				finish();
				break;

			case UiConstant.NODES_ACTION_COPY_TEMA_CANCEL:// 批量转存到团队空间(取消自动重命名)
				setResult(UiConstant.NODES_ACTION_COPY_TEMA_CANCEL, intent);
				finish();
				break;
			}
			break;
		}
		super.onActivityResult(requestCode, resultCode, data);
	}

	@Override
	protected void onLeftClicked(View clickView) {
		setResult(IntentConstant.INTENT_RESPONSE_SEARCH_TARGET_NULL, intent);
		finish();
	}

	public void setTitleText(String title) {
		currentTitle.setText(title);
	}
}
